<%-- 
    Document   : createFolder
    Created on : 2014年3月13日, 下午09:01:15
    Author     : Cho
--%>

<%@page import="db.Database"%>
<%@page import="java.io.File"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>

<%
    int lastId = 0;
    try {
        String fullPath = "/" + request.getParameter("folderName");
        ResultSet rs;
        String sql = "";
        String parentId = request.getParameter("parentId");
        if (request.getParameter("parentId") != null) {

            sql = "SELECT * FROM filefolders WHERE id=" + parentId;
            rs = Database.getResultSet(sql);
            if (rs.next()) {
                fullPath = rs.getString("fullpath") + fullPath;
            }
            rs.close();

        }
        sql = "INSERT INTO filefolders(name,username,parentId,fullpath) VALUES('" + request.getParameter("folderName") + "','"
                + session.getAttribute("user") + "',"
                + request.getParameter("parentId") + ",'"
                + fullPath + "')";

        lastId = Database.updateSql(sql);

    } catch (Exception e) {
        out.println(e);
    } finally {
        response.sendRedirect("listFiles.jsp?parentId=" + lastId);
    }
%>
